Provides routines for reading and writing data_table objects from and to delimited text files (e.g. CSV files).
Both routines touch the disk exactly once: the reader loads the entire file with a single stream read and parses it in memory, and the writer assembles the entire file in memory before a single stream write.
Reads a delimited text file into a data_table.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | fname |
The name of the file to read. |
||
| type(data_table), | intent(out) | :: | table |
The resulting data_table, holding one column per field. |
||
| character(len=1), | intent(in), | optional | :: | delimiter |
The field delimiter. The default is a comma. The delimiter must not be a double quote, carriage return, or line feed. |
|
| integer(kind=int32), | intent(in), | optional | :: | header_row |
The one-based row, counting blank rows, holding the column names. Rows above the header are ignored, and data begins on the row after the header. The default is 1. Use 0 for files without a header; the columns are then named column_1, column_2, and so on, and the column count is the largest number of fields found in any row. |
Writes a data_table to a delimited text file, replacing any existing file.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | fname |
The name of the file to write. |
||
| class(data_table), | intent(in) | :: | table |
The data_table to write. |
||
| character(len=1), | intent(in), | optional | :: | delimiter |
The field delimiter. The default is a comma. The delimiter must not be a double quote, carriage return, or line feed. |
|
| logical, | intent(in), | optional | :: | write_header |
Set to true to write the column names as the first row, or false to omit them. The default is true. |
|
| character(len=*), | intent(in), | optional | :: | real_fmt |
An optional Fortran edit descriptor, without parentheses, used for real values (e.g. "ES24.16E3" for full double precision). If omitted, the real_column default formatting is used. |